/**
 * ReportGear(2011)
 */
package net.abbp.report.view.cell.editor;

import java.awt.Component;

import net.abbp.report.model.Cell;
import net.abbp.report.view.cell.value.FormulaValue;
import net.abbp.report.view.grid.Grid;

import com.reportgear.core.swing.pane.base.JBaseDialog;

/**
 * 公式单元格编辑器
 * 
 * @version 1.0 2011-4-4
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since ReportGear 1.0
 */
public class FormulaEditor extends AbstractCellEditor {
	// 公式内容
	public FormulaValue value;

	public Object getCellEditorValue() {
		return value;
	}

	public Component getCellEditorComponent(Grid grid, Cell cell) {
		FormulaPane editorPane = new FormulaPane();

		Object o = cell.getValue();

		if (o instanceof FormulaValue) {
			this.value = (FormulaValue) o;
		} else {
//			cell.setValue(this.value = new FormulaObject());
		}

		editorPane.populate(this.value);

		int result = editorPane.showDialog(grid);

		if (result == JBaseDialog.RESULT_OK) {
			this.value = editorPane.update();
		}

		return null;
	}
}
